import junit.framework.TestCase;
/**
 * class for testing the methods in Position.java.
 * @author oi11mhn, Mattias Hinnerson.
 */

public class TestPosition extends TestCase {

	/** testing that it works to create a position in the matrix and that the 
	*   method getX works, and that creating a position outside the matrix 
	*   returns -1.
	*/
	
	private Position pos1 = new Position(1,1);
	private Position pos2 = new Position(-1,-1);
	private Position pos3 = new Position(67,87);
	
	public void testGetX() {
		
		assertNotNull(pos1.getX());
		assertEquals(pos1.getX(),1);
		
		int outsideTheBox = pos2.getX();
		assertNotNull(outsideTheBox);
		int negative = -1;
		assertEquals(outsideTheBox,negative);
		
		int outsideTheBox2 = pos3.getX();
		assertNotNull(outsideTheBox2);
		assertEquals(outsideTheBox2,negative);
		
	}
	/** testing that it works to create a position in the matrix and that the 
	*   method getY works, and that creating a position outside the matrix 
	*   returns -1.
	*/
	public void testGetY() {
		
		assertNotNull(pos1.getY());
		assertEquals(pos1.getY(),1);
		
		int outsideTheBox = pos2.getY();
		assertNotNull(outsideTheBox);
		int negative = -1;
		assertEquals(outsideTheBox,negative);
		
		int outsideTheBox2 = pos3.getY();
		assertNotNull(outsideTheBox2);
		assertEquals(outsideTheBox2,negative);
	}
	/**
	 * Testing that getPosSouth() returns the right position.
	 */
	public void testGetPosToSouth() {
		
		Position posSouth = new Position(1,2);
		assertEquals(posSouth.getX(),pos1.getPosToSouth().getX());
		assertEquals(posSouth.getY(),pos1.getPosToSouth().getY());
		
	}
	/**
	 * Testing that getPosNorth() returns the right position.
	 */
	public void testGetPosToNorth() {
		Position posNorth = new Position(1,0);
		assertEquals(posNorth.getX(),pos1.getPosToNorth().getX());
		assertEquals(posNorth.getY(),pos1.getPosToNorth().getY());
	}
	/**
	 * Testing that getPosWest() returns the right position.
	 */
	public void testGetPosToWest() {
		Position posWest = new Position(0,1);
		assertEquals(posWest.getX(),pos1.getPosToWest().getX());
		assertEquals(posWest.getY(),pos1.getPosToWest().getY());
	}
	/**
	 * Testing that getPosEast() returns the right position.
	 */
	public void testGetPosToEast() {
		Position posEast = new Position(2,1);
		assertEquals(posEast.getX(),pos1.getPosToEast().getX());
		assertEquals(posEast.getY(),pos1.getPosToEast().getY());
	}
	/**
	 * Testing that getPosSouthEast() returns the right position.
	 */
	public void testGetPosToSouthEast() {
		Position posSouthEast = new Position(2,2);
		assertEquals(posSouthEast.getX(),pos1.getPosToSouthEast().getX());
		assertEquals(posSouthEast.getY(),pos1.getPosToSouthEast().getY());
	}
	/**
	 * Testing that getPosNorthWest() returns the right position.
	 */
	public void testGetPosToNorthWest() {
		Position posNorthWest = new Position(0,0);
		assertEquals(posNorthWest.getX(),pos1.getPosToNorthWest().getX());
		assertEquals(posNorthWest.getY(),pos1.getPosToNorthWest().getY());
	}
	/**
	 * Testing that getPosSouthWest() returns the right position.
	 */
	public void testGetPosToSouthWest() {
		Position posSouthWest = new Position(0,2);
		assertEquals(posSouthWest.getX(),pos1.getPosToSouthWest().getX());
		assertEquals(posSouthWest.getY(),pos1.getPosToSouthWest().getY());
	}
	/**
	 * Testing that getPosNorthEast() returns the right position.
	 */
	public void testGetPosToNorthEast() {
		Position posNorthEast = new Position(2,0);
		assertEquals(posNorthEast.getX(),pos1.getPosToNorthEast().getX());
		assertEquals(posNorthEast.getY(),pos1.getPosToNorthEast().getY());
	}
	/**
	 * Testing that EqualObjects returns false if the in parameter is not the 
	 * same as the specified position (x:1,y:1). Otherwise if they are equal, 
	 * it should return true.
	 */
	public void testEqualsObject() {
		
		//trying to send in different kinds of positions.
		
		assertFalse(pos1.equals(pos2));
		
		//trying to send in the same position. true is expected.
		Position comparePos = new Position(1,1);
		assertTrue(pos1.equals(comparePos));
		
	}
	/**
	 *Testing that the hashCode returns the same code as the manually set 
	 *value,for the position (x:1,y:1).
	 */
	public void testHashCode() {
		int manuallySetKey = ((1+1)*33)^(1+1);
		int automaticSetKey = pos1.hashCode();
		assertEquals(manuallySetKey,automaticSetKey);
	}
}